package com.cy.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cy.common.entity.Result;
import com.cy.entity.Book;
import com.cy.entity.BookDictionary;
import com.cy.entity.Dictionary;
import com.cy.service.BookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author : 残影
 * @Date: 2021-02-23 14:11
 */
@RestController
@RequestMapping("/book")
@Api(tags = "英语教程阶段模块")
public class BookController {
    @Autowired
    private BookService bookService;

    @ApiOperation("查询所有阶段教程")
    @GetMapping("/getList")
    public Result getBookList(){
        QueryWrapper<Book> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByAsc("orders");
        List<Book> bookList= bookService.list(queryWrapper);
        return Result.ok("查询成功",bookList);
    }

    @ApiOperation("根据书本id查询章节")
    @GetMapping("/chapter/{bookId}")
    public Result bookDictionaryList(@PathVariable String bookId){
        List<BookDictionary> bookDictionaryList= bookService.getchapterByBookId(bookId);
        return Result.ok("查询成功",bookDictionaryList);
    }

    @ApiOperation("根据书本id和章节名称查询词汇")
    @GetMapping("/getVocabulary")
    public Result getVocabulary(@RequestParam String bookId,@RequestParam String tag){
        List<Dictionary> dictionaryList = bookService.getVocabulary(bookId,tag);
        return Result.ok("查询成功",dictionaryList);
    }
}
